package com.wzvtc.vsl.securitytool;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

import com.wzvtc.vsl.securitytool.ui.SettingItemView;

public class SettingActivity extends Activity {
    private SettingItemView siv_update;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        sp = getSharedPreferences("config", MODE_PRIVATE);
        siv_update = (SettingItemView) findViewById(R.id.siv_update);
        siv_update.setTitle("是否打开自动更新");
        if (sp.getBoolean("update", false)) {
            siv_update.setChecked(true);
            siv_update.setDesc("自动更新已经打开");
        } else {
            siv_update.setChecked(false);
            siv_update.setDesc("自动更新已经关闭");
        }
        siv_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor editor = sp.edit();
                if (siv_update.isChecked()) {
                    siv_update.setChecked(false);
                    siv_update.setDesc("自动更新已经关闭");
                    editor.putBoolean("update", false);
                } else {
                    siv_update.setChecked(true);
                    siv_update.setDesc("自动更新已经打开");
                    editor.putBoolean("update", true);
                }
                editor.commit();
            }
        });
    }

}
